package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.domain.BizManufacturer;
import com.cykj.pos.service.IBizManufacturerService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 制造商Controller
 *
 * @author Zephyr
 * @date 2025-05-28
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/manufacturer" )
public class BizManufacturerController extends BaseController {

    private final IBizManufacturerService iBizManufacturerService;

    /**
     * 查询制造商列表
     */
    @PreAuthorize("@ss.hasPermi('pos:manufacturer:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizManufacturer bizManufacturer) {
        startPage();
        List<BizManufacturer> list = iBizManufacturerService.queryList(bizManufacturer);
        return getDataTable(list);
    }

    /**
     * 导出制造商列表
     */
    @PreAuthorize("@ss.hasPermi('pos:manufacturer:export')" )
    @Log(title = "制造商" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(BizManufacturer bizManufacturer) {
        List<BizManufacturer> list = iBizManufacturerService.queryList(bizManufacturer);
        ExcelUtil<BizManufacturer> util = new ExcelUtil<BizManufacturer>(BizManufacturer.class);
        return util.exportExcel(list, "manufacturer" );
    }

    /**
     * 获取制造商详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:manufacturer:query')" )
    @GetMapping(value = "/{id}/{mId}" )
    public AjaxResult getInfo(@PathVariable("id" ) Integer id,@PathVariable("mId" ) Integer mId) {
        return AjaxResult.success(iBizManufacturerService.getInfoById(id,mId));
    }

    /**
     * 新增制造商
     */
    @PreAuthorize("@ss.hasPermi('pos:manufacturer:add')" )
    @Log(title = "制造商" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizManufacturer bizManufacturer) {
        return iBizManufacturerService.addBizManufacturer(bizManufacturer);
    }

    /**
     * 修改制造商
     */
    @PreAuthorize("@ss.hasPermi('pos:manufacturer:edit')" )
    @Log(title = "制造商" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizManufacturer bizManufacturer) {
        return iBizManufacturerService.updateBizManufacturer(bizManufacturer);
    }

    /**
     * 删除制造商
     */
    @PreAuthorize("@ss.hasPermi('pos:manufacturer:remove')" )
    @Log(title = "制造商" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(iBizManufacturerService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
